package com.tf_cut.backend.platform.service.impl;


import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.common.service.CommonServiceImpl;
import com.tf_cut.backend.mapper.RechargeMapper;
import com.tf_cut.backend.platform.pojo.Recharge;
import com.tf_cut.backend.platform.repository.RechargeRepository;
import com.tf_cut.backend.platform.service.RechargeService;
import com.tf_cut.backend.platform.vo.RechargeVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Service
@Transactional
@Slf4j
public class RechargeServiceImpl extends CommonServiceImpl<RechargeVo, Recharge, String> implements RechargeService {

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private RechargeRepository rechargeRepository;
    @Autowired
    private RechargeMapper rechargeMapper;

    @Override
    public PageInfo<RechargeVo> queryRechargeList(RechargeVo rechargeVo) {
        com.github.pagehelper.PageHelper.startPage(rechargeVo.getPage(), rechargeVo.getRows());
        if(StringUtils.isNotBlank(rechargeVo.getCompanyName())){
            rechargeVo.setCompanyNameLike("%" + rechargeVo.getCompanyName() + "%");
        }
        List<RechargeVo> list = rechargeMapper.queryRechargeList(rechargeVo);
        com.github.pagehelper.PageInfo<RechargeVo> pageInfo = new com.github.pagehelper.PageInfo<>(list);

        PageInfo<RechargeVo> returnPageInfo = new PageInfo<>();
        returnPageInfo.setPage(pageInfo.getPageNum());
        returnPageInfo.setPageSize(pageInfo.getPageSize());
        returnPageInfo.setRows(pageInfo.getList());
        returnPageInfo.setRecords((int) pageInfo.getTotal());
        returnPageInfo.setTotal(pageInfo.getPages());
        return returnPageInfo;
    }

    @Override
    public void updateRecharge(RechargeVo rechargeVo) {
        rechargeMapper.updateRecharge(rechargeVo);
    }
    
    @Override
    public List<RechargeVo> queryByMoney(String sellerName){
    	return rechargeMapper.queryByMoney(sellerName);
    }

	@Override
	public List<RechargeVo> queryRechargeExportList(String sellerName) {
		
		RechargeVo rechargeVo = new RechargeVo();
		if(StringUtils.isNotBlank(sellerName)){
            rechargeVo.setCompanyNameLike("%" + sellerName + "%");
        }
		return rechargeMapper.queryRechargeList(rechargeVo);
	}
}
